package view;


import sun.font.FontDesignMetrics;

import javax.swing.*;
import java.awt.*;

/***
 * Author: Mr.Zhao, Time: 2018/5/5/15:06
 * Description: 用来选择对战玩家的界面
 */
public class FindPlayerPanel extends JPanel {

    /* 查找在线玩家的按钮 */
    private JButton btn_findPlayers = null;
    /* 邀请玩家按钮 */
    private JButton btn_invite = null;
    private JScrollPane scrollPane = null;
    private ChessBoard chessBoard = null;
    /* 用于存放玩家信息 */
    private JList<String> jList = null;
    private JLabel myInfo = null;

    public FindPlayerPanel() {
        chessBoard = ChessBoard.getInstance();
        int panelWidth = (int) (chessBoard.getWidth() / 2.6);
        int panelHeight = chessBoard.getCellHeight() * ChessBoard.HEIGHT;

        Font btnFont = new Font("宋体", Font.BOLD, chessBoard.getCellHeight() / 5);
        FontMetrics btn_fm = FontDesignMetrics.getMetrics(btnFont);
        int btnHeight = btn_fm.getHeight();

        myInfo = new JLabel("我的ID：");
        Font infoFont = new Font("宋体", Font.PLAIN, chessBoard.getCellHeight() / 4);
        FontMetrics fm1 = FontDesignMetrics.getMetrics(infoFont);
        myInfo.setFont(infoFont);
        myInfo.setSize(panelWidth, fm1.getHeight());
        myInfo.setLocation(0, 0);

        btn_findPlayers = new JButton("寻找在线玩家");
        btn_findPlayers.setFont(btnFont);
        btn_findPlayers.setSize(panelWidth, btnHeight);
        btn_findPlayers.setLocation(0, myInfo.getHeight());

        jList = new JList<>();
        Font jlFont = new Font("宋体", Font.PLAIN, chessBoard.getCellHeight() / 5);
        jList.setFont(jlFont);
        jList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        scrollPane = new JScrollPane(jList);

        scrollPane.setSize(panelWidth,
                panelHeight - myInfo.getHeight() - btnHeight * 2);
        scrollPane.setLocation(0, btn_findPlayers.getY() + btn_findPlayers.getHeight());

        btn_invite = new JButton("发起邀请");
        btn_invite.setEnabled(false);
        btn_invite.setFont(btnFont);
        btn_invite.setSize(panelWidth, btn_fm.getHeight());
        btn_invite.setLocation(0, scrollPane.getY() + scrollPane.getHeight());

        this.setLayout(null);
        this.add(myInfo);
        this.add(btn_findPlayers);
        this.add(scrollPane);
        this.add(btn_invite);
        this.setSize(panelWidth, panelHeight);

    }


    public JButton getBtn_findPlayers() {
        return btn_findPlayers;
    }

    public JList<String> getjList() {
        return jList;
    }

    public JButton getBtn_invite() {
        return btn_invite;
    }

    public JLabel getMyInfo() {
        return myInfo;
    }
}
